package View;

import java.awt.Font;
import java.awt.event.ActionListener;
import java.io.Serializable;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

/** this class provide GUI window in order to add and delete cities from the DB **/
public class HandleCityView extends JFrame implements Serializable{
	
	private static final long serialVersionUID = 42L;
	/** Required fields and buttons **/
	JButton btnAdd;
	JButton btnDelete;
	JButton btnCancel;
	public JTextField CityIdFielD;
	public JTextField CityNameField;
	JLabel CityIDLbl;
	JLabel CityNameLbl;
	
	/** default and only constructor **/
	public HandleCityView() {	
		
		setTitle("Handle City List");
		getContentPane().setLayout(null);
		this.setSize(399,326);		
		this.setLocationRelativeTo(null);
		
		CityIDLbl = new JLabel("Enter City ID");
		CityIDLbl.setBounds(64, 39, 131, 20);
		CityIDLbl.setFont(new Font("Tahoma", Font.BOLD, 14));;
		getContentPane().add(CityIDLbl);
		
		CityNameLbl = new JLabel("Enter City Name");
		CityNameLbl.setFont(new Font("Tahoma", Font.BOLD, 14));
		CityNameLbl.setBounds(64, 100, 131, 20);
		getContentPane().add(CityNameLbl);
		
		
		CityIdFielD = new JTextField();
		CityIdFielD.setBounds(216, 41, 112, 20);
		getContentPane().add(CityIdFielD);
		CityIdFielD.setColumns(10);
		
		CityNameField = new JTextField();
		CityNameField.setBounds(216, 102, 112, 20);
		getContentPane().add(CityNameField);
		CityNameField.setColumns(10);
		
		btnAdd = new JButton("Add City");
		btnAdd.setFont(new Font("Tahoma", Font.BOLD, 14));
		btnAdd.setBounds(64, 151, 112, 36);
		getContentPane().add(btnAdd);
		
		btnDelete = new JButton("Delete City");
		btnDelete.setFont(new Font("Tahoma", Font.BOLD, 14));
		btnDelete.setBounds(205, 151, 112, 36);
		getContentPane().add(btnDelete);
		
		btnCancel = new JButton("Cancel");
		btnCancel.setFont(new Font("Tahoma", Font.BOLD, 16));
		btnCancel.setBounds(128, 222, 127, 46);
		getContentPane().add(btnCancel);
	}
	

	/**
	 * add action listeners to the required buttons function
	 * @param actionListener
	 */
	public void addHandleCityListener(ActionListener actionListener){
		
		
		btnAdd.addActionListener(actionListener);
		btnDelete.addActionListener(actionListener);
		btnCancel.addActionListener(actionListener);
	
	}
	/** show and hide window functions **/
	public void showWindow(){
		setVisible(true);
	}
	public void hideWindow(){
		setVisible(false);
	}	
	

	/**
	 * 
	 * @return button btnDelete
	 */
	public JButton getbtnAdd() {
		return  this.btnAdd;
	}
	/**
	 * 
	 * @return button btnDelete
	 */
	public JButton getbtnDelete() {
		return  this.btnDelete;
	}
	/**
	 * 
	 * @return button btnCancel
	 */
	public JButton getbtnCancle() {
		return  this.btnCancel;
	}
	
	/**
	 * 
	 * @return field text CityIdFielD
	 */
	public String getCityID()
	{
		return CityIdFielD.getText().toString();
	}
	/**
	 * 
	 * @return field text CityNameField
	 */
	public String getCityName()
	{
		return CityNameField.getText().toString();
	}
	
	/**
	 * clears the fields
	 */
	public void clearFields(){
		CityIdFielD.setText("");					
		CityNameField.setText("");
	}
}

